//
//  LonglinkManager.cpp
//  tarsim
//
//  Created by lanhy on 2022/3/22.
//

#include "LonglinkManager.h"
#include "log.h"

void LongLinkManager:addClientContext(uint32_t uid, LongLinkPtr link)
{
    std::lock_guard<std::mutex> guard(_mutex);
    _mapLonglink[uid] = link;
    
    DEBUG("uid:"<<uid<<" clientId:"<<context.clientId);
}

void LongLinkManager:removeClientContext(uint32_t uid)
{
    std::lock_guard<std::mutex> guard(_mutex);
    _mapLonglink.erase(uid);
    
    DEBUG("uid:"<<uid<<" clientId:"<<context.clientId);
}

LongLinkPtr LongLinkManager:getClientContext(uint32_t uid)
{
    std::lock_guard<std::mutex> guard(_mutex);
    auto itFind = _mapLonglink.find(uid);
    if (itFind == _mapLonglink.end()){
        return false;
    }
    
    DEBUG("uid:"<<uid<<" clientId:"<<itFind->second.context.clientId);
    return itFind->second;
}
